"use strict";
toastr.options = {
  closeButton: false,
  debug: false,
  progressBar: true,
  positionClass: "toast-top-center",
  onclick: null,
  showDuration: "300",
  hideDuration: "1000",
  timeOut: "2000",
  extendedTimeOut: "1000",
  showEasing: "swing",
  hideEasing: "linear",
  showMethod: "fadeIn",
  hideMethod: "fadeOut"
};
var geeurlcodeObj = geeurlcodeObj();
//加载 专家详细介绍
function peopleDetail() {
  console.log(geeurlcodeObj);
  $.server({ lecturerId: geeurlcodeObj.id }, '/website/v1/lecturerDetail').then(function (res) {
    console.log(res, "专家详细介绍");
    var obj = res.result;

    var html = "<div class=\" col-md-12 col-sm-12 col-xs-12\">\n    <div class=\"describe-box\">\n        <div class=\"left-box\">\n            <img src=\"" + obj.avatar + "\">\n            <div class=\"fans-box\">\n                <img src=\"images/expertDetail/fans-1.png\">\n                <div class=\"title\">粉丝</div>\n                <div class=\"sum\">" + obj.fans + "</div>\n            </div>\n            <div class=\"fans-box fans-box-reset\">\n                <img src=\"images/expertDetail/fans-2.png\">\n                <div class=\"title\">评价</div>\n                <div class=\"sum\">" + obj.commentCount + "</div>\n            </div>\n    <div class=\"fans-box fans-box-reset\">\n                <img class='cusor' src=\"images/expertDetail/fans-3.png\" title=\"提问\" onclick='showModul1()'>\n                <div class=\"title\" onclick='showModul1()'>专家问答</div>\n                <div class=\"sum\">" + obj.questionNum + "</div>\n            </div>\n           <div class=\"fans-box fans-box-reset follow-box\">\n                <div class=\"follow-btn\" onclick=\"follow()\">\u5173\u6CE8</div>\n                <div class=\"follow-btn-alread\" onclick=\"followN()\">\u53D6\u6D88\u5173\u6CE8</div>\n            </div>\n        </div>\n        <div class=\"right-box\">\n        <div class=\"expert-title\">\n        <span class=\"name name-reset\" >" + obj.name + "/</span>\n        <span class=\"occupation\">" + obj.title + "</span>\n    </div>\n        " + obj.introduction + "\n        </div>\n    </div>\n</div>";

    $("#peopleDetail").html(html);
    if (obj.follow == 0 || !obj.follow) {
      $(".follow-btn").show();
      $(".follow-btn-alread").hide();
    } else {
      $(".follow-btn").hide();
      $(".follow-btn-alread").show();
    }
  });
}
function showModul1(){
  $("#modul_1").css("display","flex")
}
function showModul2(){
  $("#modul_2").css("display","flex")
}
//加载研究成果
function consulting() {
  $.server({ lecturerId: geeurlcodeObj.id, contentType: 1, pageSize: 10, pageNum: 1 }, '/website/v1/lecturerContent').then(function (res) {
    console.log(res, "行业新闻");
    var obj = res.result.data;
    var html = '',
        length = obj.length > 6 ? 6 : obj.length;
    for (var i = 0; i < length; i++) {
      html += `<div class="list-box">
      <div style="width: 236px;">
      <img src="${obj[i].poster}" style="width: 236px;height: 144px;" alt="">
      </div>
      <div class="right-box" onclick="goNewsDetail(${obj[i].contentId},'专家','研究报告')">
          <div class="expertDetail-title-box">
              <div class="title" >${obj[i].title}</div>
          </div>
          <div class="expertDetail-constent">${obj[i].description}</div>
          <div class="list-bottom-box">
              <div>${obj[i].createTime}</div>
              <div class="time-box">
                  <img src="images/expertDetail/fans-2.png" style="width: 16px;height: 16px;margin-right: 5px;">
                  <div>${obj[i].hit}</div>
              </div>
          </div>
      </div>
  </div>`
      {/* html += "<a onclick=\"goNewsDetail(" + obj[i].contentId + ",'\u4E13\u5BB6','\u76F8\u5173\u8D44\u8BAF')\"><div class=\"topic-box title-box col-md-12 col-sm-12 col-xs-12\">\n      <div class=\"flex-box\">\n      <div class=\"around\"></div>\n      <div class=\"topic-title\">" + obj[i].title + "</div>\n      </div>\n      <div class=\"more\">" + obj[i].createTime.substring(5, 10) + "</div>\n      </div></div>"; */}
    }
    $("#consulting").html(html);
  });
}

//加载研究报告
function expertReport() {
  // lecturerId待定
  var params = { lecturerId: geeurlcodeObj.id, contentType: 3, pageSize: 100, pageNum: 1 };
  $.server(params, '/website/v1/lecturerContent').then(function (res) {
    console.log(res, "研究报告");
    var obj = res.result.data;
    var html = '',
        length = obj.length > 8 ? 8 : obj.length;
    for (var i = 0; i < length; i++) {
      html += "<a onclick=\"goNewsDetail(" + obj[i].contentId + ",'\u4E13\u5BB6','\u7814\u7A76\u62A5\u544A')\"><div class=\"coolleges-w-box col-md-3 col-sm-3 col-xs-3\">\n    <div class=\"topic-box expert-reset col-md-12 col-sm-12 col-xs-12\" style=\"width:281.52px;height:144.77px\">\n        <img class=\"book-img\" src='" + obj[i].poster + "'>\n        <div class=\"word-box book-reset\">\n            <div class=\"name-box mouseMethod\">" + obj[i].title + "</div>\n            <div class=\"description\">" + obj[i].author + "\u793E</div>\n        </div>\n    </div>\n</div></div>";
    }
    $("#expertReport").html(html);
  });
}

function loadClass() {
  $.server({ lecturerId: geeurlcodeObj.id }, '/website/v1/lecturerCourse').then(function (res) {
    var obj = res.result;
    var html = '',
        length = obj.length > 2 ? 2 : obj.length;
    for (var i = 0; i < length; i++) {
      var priceHtml = "";
      if (obj[i].priceStr == 0) {
        priceHtml = "<span>免费</span>";
      } else {
        priceHtml = "<span>\uFFE5" + obj[i].priceStr + "</span>";
      }
      // html+=`<li> <span class='squere'></span><a>${obj[i].title}</a>  <span>${obj[i].time}</span></li>`
      html += "<a onclick=\"goLessonDetail(" + obj[i].courseId + ")\"><div class=\"classFox classBox-reset\">\n                <img src=\"" + obj[i].poster + "\" alt=\"\">\n                <div class=\"className\">" + obj[i].title + "</div>\n                <div class=\"classnum\">\u5171" + obj[i].catalogCount + "\u8282</div>\n                <div class=\"classpirce\">" + priceHtml + " " + obj[i].buyCount + "\u4EBA\u8D2D\u4E70</div>\n            </div></div>";
    }
    $("#classBox").html(html);
  });
}
/**
 * 跳转到直播详情
 */
function goLessonDetail(id) {
  location.href = "trainDetail.html?id=" + id + "&route=2";
}

// 关注部分
function follow() {
  validLogin();
  $.server({ followId: geeurlcodeObj.id }, '/iagent/v1/follow').then(function (res) {
    $(".follow-btn").hide();
    $(".follow-btn-alread").show();
  });
}
function followN() {
  console.log("241");
  validLogin();
  $.server({ followId: geeurlcodeObj.id }, '/iagent/v1/cancelFollow').then(function (res) {
    $(".follow-btn").show();
    $(".follow-btn-alread").hide();
  });
}
function loadQuestion(){
  $.server({ lecturerId: geeurlcodeObj.id,"pageSize":100,"pageNum":1 }, '/iagent/v1/lecturerQuestions').then(function (res) {
     var detail=res.result,html='';
     for(var i=0;i<detail.length;i++){
      html+='<div class="questionBox">'+
              '<div class="qusetions">'+
              '<img src="'+detail[i].lecturerAvatar+'" alt="">'+
              '<p>'+detail[i].content+'</p>'+
              '</div>';
        for(var j=0;j<detail[i].answerList.length;j++){
          html+='<div class="answer">'+detail[i].answerList[j]+'</div>';
        }
        html+='</div>';
     }
     if(!html){
       html="暂无问答"
     }
     $("#modul_d2").html(html);
  });
}
/**
 * 页面初始化时加载 window.onload
 */
$(function () {
  consulting();
  expertReport();
  loadClass();
  peopleDetail();
  loadQuestion();
  $("#topicContent .topic-title").click(function (e) {
    var index = e.currentTarget.dataset.index;
    console.log(e);
    if (index == 1) {} else if (index == 2) {} else if (index == 3) {}
  });

  $("#researchFindings .topic-title").click(function (e) {
    var index = e.currentTarget.dataset.index;
    if (index == 1) {} else if (index == 2) {} else if (index == 3) {}
  });
  $("#sub_Btn").click(function(){
    var val=$("#text_area").val();
    if(!val){
      return toastr.info('请输入您的问题');
    }
    $.server({ "lecturerId":geeurlcodeObj.id,"question":val  }, '/iagent/v1/askQuestion').then(function (res) {
      $("#modul_1").hide();
      $("#text_area").val('')
      return toastr.info('提问成功');
    });
  })
  $("#canlcel").click(function(){
    $("#modul_1").hide();
  })
  $("#modul_d2").click(function(event){
    event.stopPropagation();
  })
  $("#modul_2").click(function(){
    $(this).hide();
  })
  $(".moreLesson").click(function(){
    location.href="train.html";
  })
});
